<?php
	class ItemList implements JsonSerializable{
		private $itemstacks = array();

		// Getters / Setters
		function getItemStacks()
		{
			return $this->itemstacks;
		}
		// End Getters / Setters

		// Public Methods
		function addItem(Item $item)
		{
			$this->addItemStack(new ItemStack($item, 1));
		}

		function addItemStack(ItemStack $itemStack)
		{
			$stack = $this->getStackForItem($itemStack->getItem());
			if($stack)
			{
				$stack->setQuantity($stack->getQuantity() + $itemStack->getQuantity());
			}
			else{
				$this->itemstacks[] = $itemStack;
			}
		}

		public function jsonSerialize()
		{;
			return $this->getItemStacks();
		}
		// End Public Methods

		// Private Methods
		private function getStackForItem(Item $item)
		{
			foreach($this->itemstacks as $stack)
			{
				if($stack->getItem() == $item){
					return $stack;
				}
			}
			return NULL;
		}
		// End Private Methods
	}
?>
